package day23;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;


/**
 *
 * TransServer.java
 * @author wangbiao<br/>
 *         email:785497344@qq.com
 * @description 文本转换服务服务端
 * @since 1.0.0
 * @date 2013-7-11下午11:17:15
 *
 */
public class TransServer {

	public static void main(String[] args) {
		ServerSocket ss = null;
		Socket s = null;
		BufferedReader in = null;
		BufferedWriter out = null;
		try {
			ss = new ServerSocket(10000);
			s = ss.accept();
			String ip = s.getInetAddress().getHostAddress();
			System.out.println(ip+"connect !");
			
			in = new BufferedReader(new InputStreamReader(s.getInputStream()));
			out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
			//以上一句的简写
			//PrintWriter writer = new PrintWriter(s.getOutputStream(), true);
			
			String line = null;
			while ((line=in.readLine()) != null) {
				System.out.println("客户端数据  "+line);
				out.write(line.toUpperCase());
				out.newLine();
				out.flush();
				//以上三句的简写
				//writer.println(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (null != ss) {
				try {
					ss.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (null != s) {
				try {
					s.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
